﻿/*
 * Crée par SharpDevelop.
 * Utilisateur: Olivier
 * Date: 2013-05-04
 * Heure: 11:38
 * 
 * Pour changer ce modèle utiliser Outils | Options | Codage | Editer les en-têtes standards.
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using GCGMain.TabUC;

namespace GCGMain
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{

        static GCGDataBaseTableLib.TaskTable TTask = new GCGDataBaseTableLib.TaskTable();
        static GCGDataBaseTableLib.DepartementTable TDepartement = new GCGDataBaseTableLib.DepartementTable();
        static GCGDataBaseTableLib.PrioriteTable TPriorite = new GCGDataBaseTableLib.PrioriteTable();
        static GCGDataBaseTableLib.EmployeTable TEmploye = new GCGDataBaseTableLib.EmployeTable();
        static GCGDataBaseTableLib.EquipeTable TEquipe = new GCGDataBaseTableLib.EquipeTable();
       

        object[,] DepartementArray = TDepartement.ListDepartementToStringArray();
        object[,] EmployeArray = TEmploye.ListEmployeToStringArray();
        object[,] PrioriteArray = TPriorite.ListPrioriteToStringArray();
        object[,] EquipeArray = TEquipe.ListEquipeToStringArray();


        Task_Network_Center.General.isNewTask Task = new Task_Network_Center.General.isNewTask();
        NotifyIcon nIcon = new NotifyIcon();
        ContextMenuStrip menuStrip = new ContextMenuStrip();


		public MainWindow()
		{
			InitializeComponent();
		}
			
		void window1_Loaded(object sender, RoutedEventArgs e)
		{
            #region Timer_For_Update

            DispatcherTimer timer = new DispatcherTimer();
            timer.Tick += new EventHandler(TimerDone);
            timer.Interval = new TimeSpan(0, GCGGeneralLib.GeneralVar.NotifyDelay, 0);
            timer.Start();

            #endregion

            #region NotifyIcon&MenuStrip

            menuStrip.Items.Add("Vérifier nouvelles tâches", null, menuStripCheck_Click);
            menuStrip.Items.Add("Quitter", null, menuStripQuitter_Click);

            nIcon.BalloonTipTitle = "GCG-Suite";
            nIcon.BalloonTipText = "Une nouvelle tâche a eter ajouté pour vous.";
            nIcon.Text = "Notification de nouvelle tâches";
            nIcon.Icon = Properties.Resources.Document;
            nIcon.Visible = true;
            nIcon.DoubleClick += new EventHandler(nIcon_DoubleClick);
            nIcon.BalloonTipClicked += new EventHandler(nIcon_BallonClick);
            nIcon.ContextMenuStrip = menuStrip;
            #endregion

            if (GCGGeneralLib.GeneralVar.initialID == 1 || GCGGeneralLib.GeneralVar.initialID == 2|| GCGGeneralLib.GeneralVar.initialID == 3
                || GCGGeneralLib.GeneralVar.initialID == 19 || GCGGeneralLib.GeneralVar.initialID == 24 || GCGGeneralLib.GeneralVar.initialID == 29 || GCGGeneralLib.GeneralVar.initialID == 30)
            {
                mnuConfigTable.IsEnabled = true;
            }
		}

        private void lblTAG_MouseUp(object sender, MouseButtonEventArgs e)
        {
            //var tab = new TabItem();
            //tab.Header = "TAG";
            ClosableTab tab = new ClosableTab();
           
            tab.Title = "TAG   ";
            Task_Network_Center.MainWindow main = new Task_Network_Center.MainWindow();


            tab.Content = main;
            tabMain.Items.Add(tab);
            tab.Focus();
        }

        public void menuStripQuitter_Click(object sender, EventArgs e)
        {
            System.Windows.Application.Current.Shutdown();
        }

        public void menuStripCheck_Click(object sender, EventArgs e)
        {

            //updateFilter();
            //updateCbo(false);
            if (Task.CheckForNewTask(GCGGeneralLib.GeneralVar.initialID))
            {
                nIcon.ShowBalloonTip(10000);
            }

        }


        public void nIcon_BallonClick(object sender, EventArgs e)
        {
            // this.WindowState = WindowState.Maximized;
        }

        public void nIcon_DoubleClick(object sender, EventArgs e)
        {
            //if (this.WindowState == WindowState.Minimized)
            //{
            //  this.WindowState = WindowState.Maximized;

            // }

        }


        public void TimerDone(object sender, EventArgs e)
        {

            if (GCGGeneralLib.GeneralVar.Notify)
            {
                //updateFilter();
                //updateCbo(false);
                if (Task.CheckForNewTask(GCGGeneralLib.GeneralVar.initialID))
                {
                    nIcon.ShowBalloonTip(10000);
                }
            }
        }

        private void window1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            nIcon.Visible = false;
            nIcon.Dispose();
            nIcon = null;
        }

        private void lblTAG_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            lblTAG.Foreground = Brushes.Gray;
        }

        private void lblTAG_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            lblTAG.Foreground = Brushes.Black;
        }

        private void mnuQuitter_click(object sender, RoutedEventArgs e)
        {
            System.Windows.Application.Current.Shutdown();
        }

        private void mnuconfigGeneral_click(object sender, RoutedEventArgs e)
        {
            FrmConfigGeneral config = new FrmConfigGeneral();
            config.Loaded += new RoutedEventHandler(config_load);
            config.Closed += new EventHandler(config_closed);
            config.TempEmployeArray = EmployeArray;
            config.Show();
        }

        void config_load(object sender, RoutedEventArgs e)
        {
            this.IsEnabled = false;
        }

        void config_closed(object sender, EventArgs e)
        {
            this.IsEnabled = true;

        }

        private void mnuConfigTable_Click(object sender, RoutedEventArgs e)
        {
            FrmConfigTable configTable = new FrmConfigTable();
            configTable.Loaded += new RoutedEventHandler(configTable_load);
            configTable.Closed += new EventHandler(configTable_closed);
            configTable.TempEquipeArray = EquipeArray;
            configTable.TempDepartementArray = DepartementArray;
            configTable.Show();
        }

        void configTable_load(object sender, RoutedEventArgs e)
        {
            this.IsEnabled = false;
        }

        void configTable_closed(object sender, EventArgs e)
        {
            this.IsEnabled = true;
            DepartementArray = TDepartement.ListDepartementToStringArray();
            EmployeArray = TEmploye.ListEmployeToStringArray();
            PrioriteArray = TPriorite.ListPrioriteToStringArray();
            EquipeArray = TEquipe.ListEquipeToStringArray();
        }

        private void mnuAide_Click(object sender, RoutedEventArgs e)
        {
            FrmAide aide = new FrmAide();
            aide.Loaded += new RoutedEventHandler(aide_load);
            aide.Closed += new EventHandler(aide_closed);
            aide.Show();
        }

        void aide_load(object sender, RoutedEventArgs e)
        {
            this.IsEnabled = false;
        }

        void aide_closed(object sender, EventArgs e)
        {
            this.IsEnabled = true;

        }

        private void mnuApropos_Click(object sender, RoutedEventArgs e)
        {
            FrmAbout apropos = new FrmAbout();
            apropos.Loaded += new RoutedEventHandler(apropos_load);
            apropos.Closed += new EventHandler(apropos_closed);
            apropos.Show();
        }

        void apropos_load(object sender, RoutedEventArgs e)
        {
            this.IsEnabled = false;
        }

        void apropos_closed(object sender, EventArgs e)
        {
            this.IsEnabled = true;

        }
	}
}